package com.atqar.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CASHello {
    public static void main(String[] args) {
        //atomicinteger可以设置内存位置,预期值和更新值,挡内存位置和预期值相同,就会将当前位置的值改为更行值
                                                       //内存位置
        AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.get());

                                   //预期值和更新值
        atomicInteger.compareAndSet(5,666);
        atomicInteger.compareAndSet(5,777);

        System.out.println(atomicInteger);

        System.out.println(atomicInteger.getAndIncrement());//666
        System.out.println(atomicInteger.incrementAndGet());//668
        System.out.println(atomicInteger.addAndGet(2));//670
    }
}
